<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<!doctype html>

<html lang="en">
<head>
<meta charset="utf-8">
<title></title>
<meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="">
<meta name="author" content="">




</head>
<body class=" theme-blue">
	<script src="${pageContext.request.contextPath}/lib/jquery.min.js"></script>
	<%-- <script src="${pageContext.request.contextPath}/lib/bootstrap/js/bootstrap.min.js"></script> --%>
	<script
		src="${pageContext.request.contextPath}/lib/bootstrap-switch.js"></script>


	<script type="text/javascript">
		$(function(argument) {
			$('[type="checkbox"]').bootstrapSwitch();
		})

		function isChange(e) {
			var state = 0;
			if (!e.checked) {
				state = 1;
			}
			
				$.ajax({
					url : '${pageContext.request.contextPath}/subject/state',
					data : {
						subState : state,
						subId : e.id
					},
					type : 'post',
					async : true,
					dataType : 'json',
					success : function(data) {
						if(data == "0"){
							alert("关闭考试！");
						}else if(data == "1"){
							alert("开启考试！");
						}
					},
					error : function() {
						alert("异常！");
					}
				})
			}
		

		$(document).ready(function() {

			$("#message").delay(1500).slideUp("normal");

			$("#user").click(function() {
				$.confrim({
					title : 'Confirm!',
					content : 'Confirm! Confirm! Confirm!',
					confirm : function() {
						alert('the user clicked confirm');
					},
					cancel : function() {
						alert('the user clicked cancel')
					}
				});
			});

		});

		function isDelete() {
			if (window.confirm("Are you sure delete?"))

				return true;
			else {
				return false;
			}

		}
	</script>

	<div class="content">
		<c:if test="${not empty message}">
			<div id="message" class="alert alert-success">
				<button data-dismiss="alert" class="close">×</button>${message}</div>
		</c:if>


		<div class="header">

			<h1 class="page-title">Subjects</h1>
			<ul class="breadcrumb">
				<li><a href="index.html">Home</a></li>
				<li class="active">subject</li>
			</ul>

		</div>
		<div class="main-content">

			<%-- <div class="search-well">
                <form class="form-inline" method="post" style="margin-top:0px;" action="${pageContext.request.contextPath }/tea/search">
                    <input class="input-xlarge form-control" placeholder="Search Help..." id="appendedInputButton" name="searchTip" value="${searchTip }" type="text">
                    <button class="btn btn-default" type="submit"><i class="fa fa-search"></i> Go</button>
                </form>
            </div> --%>

			<div class="btn-toolbar list-toolbar">
				<button class="btn btn-primary">
					<i class="fa fa-plus"></i> <a
						href="${pageContext.request.contextPath}/ti/add">New Subject</a>
				</button>
				<button class="btn btn-default">
					<a href="${pageContext.request.contextPath }/upload">Import</a>
				</button>
				<button class="btn btn-default">Export</button>
				<div class="btn-group"></div>
			</div>

	


			<table class="table-striped  table table-bordered ">
				<thead>
					<tr>
						<th id="user"><spring:message code="subject.id" /></th>

						<th><spring:message code="subject.name" /></th>
						<th><spring:message code="subject.description" /></th>
						<th><spring:message code="subject.number" /></th>
						<th><spring:message code="subject.totalTime" /></th>
						<th><spring:message code="subject.sum" /></th>
						<th><spring:message code="subject.flag" /></th>
						<th><spring:message code="subject.done" /></th>
						<th style="width: 3.5em;" colspan="2"><spring:message
								code="website.operator" /></th>
					</tr>
				</thead>
				<tbody>
					<c:forEach items="${page.datas }" var="sub">
						<tr>
							<td>${sub.examSubjectId }</td>
							<td>${sub.examSubjectName }</td>
							<td>${sub.examSubjectDescription }</td>
							<td>${sub.examSubjectTnumber }</td>
							<td>${sub.examSubjectTotaltime }</td>
							<td>${sub.examSubjectSum }</td>
							<td width="125px;">
							<div style="width:100px;">
							<c:choose>

									<c:when test="${sub.examSubjectFlag eq 1 }">    <!-- 如果 -->  
										 <input class="form-control" ${readonly }
								id="${sub.examSubjectId }" onchange="isChange(this)"
								type="checkbox">
   									</c:when>

									<c:otherwise>  <!-- 否则   -->
									<input class="form-control" ${readonly }
								id="${sub.examSubjectId }" onchange="isChange(this)"
								type="checkbox" checked>
  									</c:otherwise>
								</c:choose></div></td>
							<td>
								<c:choose>
									<c:when test="${sub.examSubjectFlag eq 0 }">
										未开启考试
									</c:when>
									<c:otherwise>
										<c:choose>
											<c:when test="${sub.examSubjectDone eq 1 }">
												已考
											</c:when>
											<c:otherwise>
												<a href="${pageContext.request.contextPath}/exam/examList/${sub.examSubjectId}"><input type="button" value="开始考试"/></a>
											</c:otherwise>
										</c:choose>
									</c:otherwise>
								</c:choose>
								
							
								
							</td>
							<td><a onclick="return isDelete()"
								href="${pageContext.request.contextPath}/subject/delete/${sub.examSubjectId }"
								id="del" role="button" data-toggle="modal"> <i
									class="fa fa-trash-o"></i></a> &nbsp;<a
								href="${pageContext.request.contextPath}/subject/edit/${sub.examSubjectId}"><i
									class="fa fa-pencil"></i></a></td>
						</tr>
					</c:forEach>


					<tr>
						<td colspan="9"><jsp:include page="/common/page.jsp">
								<jsp:param value="subjectList" name="url" />
								<jsp:param value="${page.totalSize }" name="items" />
								<jsp:param value="${page.pageSize }" name="pageSize" />
							</jsp:include></td>
					</tr>
				</tbody>
			</table>
</body>
</html>
